# 给定一个列表, 根据grade来排序
classes = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]
classes.sort(key=lambda x: x["grade"])
print(classes)


# 通过filter语句来筛选出Grade为A的同学
f = filter(lambda x: True if x["grade"] == "A" else False, classes)
l = list(f)
print(l)


# 通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda)
def age_21(a):
    return a["age"]+1
m = map(age_21, classes)
n = list(m)
print(n)


# 使用递归函数重构斐波那契函数
# F(n) = F(n-2) + F(n-1)
def fact(n):
    if n <= 1:
        return n
    return fact(n-2) + fact(n-1)
